package T6_18;

public class BankAccount {
    private String name = "";
    private double balance = 0;
    private int year = 0;
    private double rate = 0.01;

    //请前往t6-18-2查看无get和set方法的代码
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
    

    BankAccount(){
        setBalance(10);
        setYear(1);
    }

    BankAccount(String name){
        setName(name);

    }
    
    BankAccount(double balance,int year){
        setBalance(balance);
        setYear(year);
    }

    BankAccount(String name,double balance,int year){
        setName(name);
        setBalance(balance);
        setYear(year);
    }

    public void save(double balance){
		setBalance(getBalance()+balance);
    }

    public void fetch(double balance) {
        System.out.println("当前余额为:" + getBalance() + ",将取走:" + balance);
        setBalance(getBalance()-balance);
    }

    public void calcTotal() {
        double sum;
        sum = getBalance()*getRate()*getYear();
        System.out.println("当前余额为:"+(getBalance()+sum));
    }

    public void show() {
        System.out.println(getName());
        System.out.println(getBalance());
        System.out.println((getBalance()*getYear()*getRate()+getBalance()));
    }
}